﻿@model Controller2.Models.Briefing
@{
    Layout = null;
}
<!DOCTYPE html>
<html class="no-js">
<head>
    <title>Cadastro</title>
    @(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.vista.css").Combined(true).Compress(true)))
    @if (false)
    {
        <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
        <link href="@Url.Content("~/Content/themes/controller/controller.css")" rel="stylesheet" type="text/css" />
        <script src="@Url.Content("~/Scripts/jquery.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>    
        <script src="@Url.Content("~/Scripts/jquery.maskedinput-1.3.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    }
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/controller.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/numbers.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    <style type="text/css">
        .display-label, .editor-label {
            width: 140px;
            text-align: right;
            padding-right: 5px;
        }

        #IdCampanha, #IdTipoCampanha {
            width: 400px;
        }

        textarea#Ata {
            width: 400px;
        }

        .error {
            color: red;
            clear: both;
            font: 10px Arial,Helvetica,sans-serif;
            height: 15px;
        }

        iframe {
            width: 100%;
            height: 100%;
        }
    </style>
    @if (false)
    {
        <script src="../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../Scripts/jquery-ui.js" type="text/javascript"></script>
        <script src="../../Scripts/controller.js" type="text/javascript"></script>
    }
</head>
<body id="frame">
    <div id="formHide">
        @using (Html.BeginForm("Salvar", "Briefing"))
        {
            @Html.ValidationSummary(true)            
            @Html.HiddenFor(model => model.IdBriefing)
            <div class="editor-label">
                @Html.LabelFor(model => model.DataReuniao, "Data Reunião: ")
            </div>
            <div class="editor-field">
                @if (Model.IdBriefing == 0)
                {
                    Model.DataReuniao = DateTime.Now;
                }
                @Html.EditorFor(model => model.DataReuniao)
                @Html.ValidationMessageFor(model => model.DataReuniao)
            </div>                
            <div class="editor-label">
                @Html.LabelFor(model => model.IdCampanha, "Campanha: ")
            </div>
            <div class="editor-field">
                @if (User.IsInRole("Cliente"))
                {
                    @Html.EditorFor(model => model.Campanha.Nome)
                }
                else
                {
                    @Html.DropDownListFor(model => model.IdCampanha, (IEnumerable<SelectListItem>)ViewBag.Campanha, String.Empty)
                }
                @Html.ValidationMessageFor(model => model.IdCampanha)
            </div>
            <div class="editor-label">
                @Html.LabelFor(model => model.TipoBriefing, "Tipo de Briefing: ")
            </div>
            <div class="editor-field">
                @if (User.IsInRole("Cliente"))
                {
                    @Html.TextBoxFor(model => model.TipoBriefing, new { style = "width: 400px;", @class = "readonly",  @readonly = "readonly" })
                }
                else
                {
                    var prospecto = "";
                    var criacao = "";
                    
                    if (Model.TipoBriefing == "Prospecto")
                    {
                        prospecto = "selected=\"selected\"";
                    }
                    else if (Model.TipoBriefing == "Criação")
                    {
                        criacao = "selected=\"selected\"";
                    }
                    
                    <select style="width: 400px;" name="TipoBriefing" id="TipoBriefing">
                        <option value=""></option>
                        <option value="Prospecto" @prospecto>Prospecto</option>
                        <option value="Criação" @criacao>Criação</option>
                    </select>            
                }
            </div>
                if (User.IsInRole("Cliente"))
                {
            <div style="width: 97%; clear: both; float: left; border: 1px solid silver; height: 390px; margin-top: 10px; padding: 5px 10px; overflow: auto;">
                @MvcHtmlString.Create(Model.Ata)
            </div>
                }
                else
                {
            <div class="editor-field">
                @(Html.Telerik().Editor()
                        .Name("Ata")
                        .Encode(false)
                        .HtmlAttributes(new { style = "height:390px;" })
                    )
            </div>
                }
            <div class="error">@Html.ValidationMessageFor(model => model.Ata)</div>
            
            <div id="botoesForm">
                @if (!User.IsInRole("Cliente"))
                {
                    <input type="submit" id="Gravar" value="Gravar" />
                }
                <input type="button" id="Fechar" value="Cancelar" />
            </div>
        }
    </div>
    <div id="alertaErro" style="display: none">
    </div>
    @if (User.IsInRole("Cliente"))
    {
        <script type="text/javascript">
            $(function () {
                $('#formHide').fadeIn('slow');
                hideLoading();
            });
            $('#Fechar').click(function () { closeWindow(); });
        </script>
    }
    else
    {
        <script type="text/javascript">
            $.validator.methods.obrigatorio = function (value, element, param) {
                if ($(element).val() != "") {
                    $('.t-editable-area').css('border-color', '#A7BAC5');
                    return true;
                } else {
                    $('.t-editable-area').css('border-color', 'red');
                    return false;
                }
            };
            $(function () {
                $('#Ata-value').rules("add", {
                    obrigatorio: true,
                    messages: {
                        obrigatorio: "Por favor, escreva uma mensagem."
                    }
                });
                $('#formHide').fadeIn('slow');                
                hideLoading();
                $('#Ata').focus();
            });
            $('form').submit(function (e) {
                e.preventDefault();
                if ($('form').valid()) {
                    $.post('@Url.Action("Salvar", "Briefing")', $('form').serialize(), function (data) {
                        if (data.salvo) {
                            closeWindow();
                        } else {
                            alertError(data.error);
                        }
                        $('#gravar').attr('disabled', false);
                    });
                }
            });
            $('#Fechar').click(function () { closeWindow(); });
        </script>
    }
</body>
</html>
